package br.com.jw.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import br.com.jw.jdbc.Pool;
import br.com.jw.modelo.Menu;

public class MenusDao{
	Connection conn;
	private Pool pool;
	PreparedStatement stmt;
	public MenusDao(Pool pool){
		this.pool=pool;
	}
	
	
	public List<Menu> listaMenus() throws ClassNotFoundException, SQLException{
		
		List<Menu> listaMenus=new ArrayList<Menu>();
		String sql="select * from menu";
		conn = pool.getConnection();
		try{
			try {
				stmt=conn.prepareStatement(sql);
				ResultSet rs=stmt.executeQuery();
				
					while(rs.next()){
						listaMenus.add(new Menu(
								rs.getInt("men_id"),
								rs.getString("men_nome")));
								
					}
					
					stmt.close();
					rs.close();
					return listaMenus;
				
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}finally{
			pool.liberarConexao(conn);
		}
		return listaMenus;
	}
}
	